Public Class frmConfigImprimir
  Inherits Click.frmBase

  Private frm As frmMain
  Private frmCPag As frmConfigPagina

#Region " Windows Form Designer generated code "

  Public Sub New()
    MyBase.New()

    'This call is required by the Windows Form Designer.
    InitializeComponent()

    'Add any initialization after the InitializeComponent() call
    frmCPag = New frmConfigPagina
  End Sub

  'Form overrides dispose to clean up the component list.
  Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
    If disposing Then
      If Not (components Is Nothing) Then
        components.Dispose()
      End If

      frmCPag.Dispose()
    End If
    MyBase.Dispose(disposing)
  End Sub

  'Required by the Windows Form Designer
  Private components As System.ComponentModel.IContainer

  'NOTE: The following procedure is required by the Windows Form Designer
  'It can be modified using the Windows Form Designer.  
  'Do not modify it using the code editor.
  Friend WithEvents GroupBox1 As System.Windows.Forms.GroupBox
  Friend WithEvents GroupBox2 As System.Windows.Forms.GroupBox
  Friend WithEvents RadioButton1 As System.Windows.Forms.RadioButton
  Friend WithEvents RadioButton2 As System.Windows.Forms.RadioButton
  Friend WithEvents RadioButton3 As System.Windows.Forms.RadioButton
  Friend WithEvents RadioButton4 As System.Windows.Forms.RadioButton
  Friend WithEvents TextBox1 As System.Windows.Forms.TextBox
  Friend WithEvents TextBox2 As System.Windows.Forms.TextBox
  Friend WithEvents Label1 As System.Windows.Forms.Label
  Friend WithEvents Button1 As System.Windows.Forms.Button
  Friend WithEvents CheckBox1 As System.Windows.Forms.CheckBox
  Friend WithEvents CheckBox2 As System.Windows.Forms.CheckBox
  Friend WithEvents CheckBox3 As System.Windows.Forms.CheckBox
  Friend WithEvents CheckBox4 As System.Windows.Forms.CheckBox
  Friend WithEvents CheckBox5 As System.Windows.Forms.CheckBox
  Friend WithEvents CheckBox6 As System.Windows.Forms.CheckBox
  Friend WithEvents CheckBox7 As System.Windows.Forms.CheckBox
  Friend WithEvents Button2 As System.Windows.Forms.Button
  Friend WithEvents Button3 As System.Windows.Forms.Button
  Friend WithEvents Button4 As System.Windows.Forms.Button
  Friend WithEvents CheckBox8 As System.Windows.Forms.CheckBox
  <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
    Dim resources As System.Resources.ResourceManager = New System.Resources.ResourceManager(GetType(frmConfigImprimir))
    Me.GroupBox1 = New System.Windows.Forms.GroupBox
    Me.Button1 = New System.Windows.Forms.Button
    Me.Label1 = New System.Windows.Forms.Label
    Me.TextBox2 = New System.Windows.Forms.TextBox
    Me.TextBox1 = New System.Windows.Forms.TextBox
    Me.RadioButton4 = New System.Windows.Forms.RadioButton
    Me.RadioButton3 = New System.Windows.Forms.RadioButton
    Me.RadioButton2 = New System.Windows.Forms.RadioButton
    Me.RadioButton1 = New System.Windows.Forms.RadioButton
    Me.GroupBox2 = New System.Windows.Forms.GroupBox
    Me.CheckBox5 = New System.Windows.Forms.CheckBox
    Me.CheckBox4 = New System.Windows.Forms.CheckBox
    Me.CheckBox3 = New System.Windows.Forms.CheckBox
    Me.CheckBox2 = New System.Windows.Forms.CheckBox
    Me.CheckBox1 = New System.Windows.Forms.CheckBox
    Me.CheckBox6 = New System.Windows.Forms.CheckBox
    Me.CheckBox7 = New System.Windows.Forms.CheckBox
    Me.CheckBox8 = New System.Windows.Forms.CheckBox
    Me.Button2 = New System.Windows.Forms.Button
    Me.Button3 = New System.Windows.Forms.Button
    Me.Button4 = New System.Windows.Forms.Button
    Me.GroupBox1.SuspendLayout()
    Me.GroupBox2.SuspendLayout()
    Me.SuspendLayout()
    '
    'GroupBox1
    '
    Me.GroupBox1.Controls.Add(Me.Button1)
    Me.GroupBox1.Controls.Add(Me.Label1)
    Me.GroupBox1.Controls.Add(Me.TextBox2)
    Me.GroupBox1.Controls.Add(Me.TextBox1)
    Me.GroupBox1.Controls.Add(Me.RadioButton4)
    Me.GroupBox1.Controls.Add(Me.RadioButton3)
    Me.GroupBox1.Controls.Add(Me.RadioButton2)
    Me.GroupBox1.Controls.Add(Me.RadioButton1)
    Me.GroupBox1.FlatStyle = System.Windows.Forms.FlatStyle.System
    Me.GroupBox1.Location = New System.Drawing.Point(8, 48)
    Me.GroupBox1.Name = "GroupBox1"
    Me.GroupBox1.Size = New System.Drawing.Size(208, 136)
    Me.GroupBox1.TabIndex = 0
    Me.GroupBox1.TabStop = False
    Me.GroupBox1.Text = "#RangosPaginas#"
    '
    'Button1
    '
    Me.Button1.FlatStyle = System.Windows.Forms.FlatStyle.System
    Me.Button1.Location = New System.Drawing.Point(108, 24)
    Me.Button1.Name = "Button1"
    Me.Button1.Size = New System.Drawing.Size(88, 20)
    Me.Button1.TabIndex = 7
    Me.Button1.Text = "&Configuracion"
    '
    'Label1
    '
    Me.Label1.Location = New System.Drawing.Point(140, 108)
    Me.Label1.Name = "Label1"
    Me.Label1.Size = New System.Drawing.Size(28, 20)
    Me.Label1.TabIndex = 6
    Me.Label1.Text = "#a#"
    Me.Label1.TextAlign = System.Drawing.ContentAlignment.MiddleCenter
    '
    'TextBox2
    '
    Me.TextBox2.Location = New System.Drawing.Point(108, 108)
    Me.TextBox2.Name = "TextBox2"
    Me.TextBox2.Size = New System.Drawing.Size(24, 20)
    Me.TextBox2.TabIndex = 5
    Me.TextBox2.Text = "1"
    '
    'TextBox1
    '
    Me.TextBox1.Location = New System.Drawing.Point(172, 108)
    Me.TextBox1.Name = "TextBox1"
    Me.TextBox1.Size = New System.Drawing.Size(24, 20)
    Me.TextBox1.TabIndex = 4
    Me.TextBox1.Text = "1"
    '
    'RadioButton4
    '
    Me.RadioButton4.Location = New System.Drawing.Point(12, 108)
    Me.RadioButton4.Name = "RadioButton4"
    Me.RadioButton4.Size = New System.Drawing.Size(92, 20)
    Me.RadioButton4.TabIndex = 3
    Me.RadioButton4.Text = "#Paginas#"
    '
    'RadioButton3
    '
    Me.RadioButton3.Location = New System.Drawing.Point(12, 80)
    Me.RadioButton3.Name = "RadioButton3"
    Me.RadioButton3.Size = New System.Drawing.Size(184, 20)
    Me.RadioButton3.TabIndex = 2
    Me.RadioButton3.Text = "#PaginaActual#"
    '
    'RadioButton2
    '
    Me.RadioButton2.Location = New System.Drawing.Point(12, 52)
    Me.RadioButton2.Name = "RadioButton2"
    Me.RadioButton2.Size = New System.Drawing.Size(184, 20)
    Me.RadioButton2.TabIndex = 1
    Me.RadioButton2.Text = "#SeleccionCeldas#"
    '
    'RadioButton1
    '
    Me.RadioButton1.Checked = True
    Me.RadioButton1.Location = New System.Drawing.Point(12, 24)
    Me.RadioButton1.Name = "RadioButton1"
    Me.RadioButton1.Size = New System.Drawing.Size(92, 20)
    Me.RadioButton1.TabIndex = 0
    Me.RadioButton1.TabStop = True
    Me.RadioButton1.Text = "#Todo#"
    '
    'GroupBox2
    '
    Me.GroupBox2.Controls.Add(Me.CheckBox5)
    Me.GroupBox2.Controls.Add(Me.CheckBox4)
    Me.GroupBox2.Controls.Add(Me.CheckBox3)
    Me.GroupBox2.Controls.Add(Me.CheckBox2)
    Me.GroupBox2.Controls.Add(Me.CheckBox1)
    Me.GroupBox2.Controls.Add(Me.CheckBox6)
    Me.GroupBox2.Controls.Add(Me.CheckBox7)
    Me.GroupBox2.Controls.Add(Me.CheckBox8)
    Me.GroupBox2.FlatStyle = System.Windows.Forms.FlatStyle.System
    Me.GroupBox2.Location = New System.Drawing.Point(224, 48)
    Me.GroupBox2.Name = "GroupBox2"
    Me.GroupBox2.Size = New System.Drawing.Size(284, 136)
    Me.GroupBox2.TabIndex = 1
    Me.GroupBox2.TabStop = False
    Me.GroupBox2.Text = "#Opciones#"
    '
    'CheckBox5
    '
    Me.CheckBox5.Checked = True
    Me.CheckBox5.CheckState = System.Windows.Forms.CheckState.Checked
    Me.CheckBox5.Location = New System.Drawing.Point(144, 24)
    Me.CheckBox5.Name = "CheckBox5"
    Me.CheckBox5.Size = New System.Drawing.Size(128, 20)
    Me.CheckBox5.TabIndex = 6
    Me.CheckBox5.Text = "#Fondo#"
    '
    'CheckBox4
    '
    Me.CheckBox4.Location = New System.Drawing.Point(144, 80)
    Me.CheckBox4.Name = "CheckBox4"
    Me.CheckBox4.Size = New System.Drawing.Size(128, 20)
    Me.CheckBox4.TabIndex = 3
    Me.CheckBox4.Text = "#Border#"
    '
    'CheckBox3
    '
    Me.CheckBox3.Location = New System.Drawing.Point(12, 80)
    Me.CheckBox3.Name = "CheckBox3"
    Me.CheckBox3.Size = New System.Drawing.Size(128, 20)
    Me.CheckBox3.TabIndex = 2
    Me.CheckBox3.Text = "#Lineas#"
    '
    'CheckBox2
    '
    Me.CheckBox2.Location = New System.Drawing.Point(12, 52)
    Me.CheckBox2.Name = "CheckBox2"
    Me.CheckBox2.Size = New System.Drawing.Size(128, 20)
    Me.CheckBox2.TabIndex = 1
    Me.CheckBox2.Text = "EncabezadosRen#"
    '
    'CheckBox1
    '
    Me.CheckBox1.Checked = True
    Me.CheckBox1.CheckState = System.Windows.Forms.CheckState.Checked
    Me.CheckBox1.Location = New System.Drawing.Point(12, 24)
    Me.CheckBox1.Name = "CheckBox1"
    Me.CheckBox1.Size = New System.Drawing.Size(128, 20)
    Me.CheckBox1.TabIndex = 0
    Me.CheckBox1.Text = "#EncabezadosCol#"
    '
    'CheckBox6
    '
    Me.CheckBox6.Location = New System.Drawing.Point(144, 52)
    Me.CheckBox6.Name = "CheckBox6"
    Me.CheckBox6.Size = New System.Drawing.Size(128, 20)
    Me.CheckBox6.TabIndex = 5
    Me.CheckBox6.Text = "#Color#"
    '
    'CheckBox7
    '
    Me.CheckBox7.Checked = True
    Me.CheckBox7.CheckState = System.Windows.Forms.CheckState.Checked
    Me.CheckBox7.Location = New System.Drawing.Point(144, 52)
    Me.CheckBox7.Name = "CheckBox7"
    Me.CheckBox7.Size = New System.Drawing.Size(128, 20)
    Me.CheckBox7.TabIndex = 4
    Me.CheckBox7.Text = "#SoloDatos#"
    '
    'CheckBox8
    '
    Me.CheckBox8.Checked = True
    Me.CheckBox8.CheckState = System.Windows.Forms.CheckState.Checked
    Me.CheckBox8.Location = New System.Drawing.Point(144, 52)
    Me.CheckBox8.Name = "CheckBox8"
    Me.CheckBox8.Size = New System.Drawing.Size(128, 20)
    Me.CheckBox8.TabIndex = 7
    Me.CheckBox8.Text = "#RenCol#"
    '
    'Button2
    '
    Me.Button2.FlatStyle = System.Windows.Forms.FlatStyle.System
    Me.Button2.Location = New System.Drawing.Point(292, 192)
    Me.Button2.Name = "Button2"
    Me.Button2.Size = New System.Drawing.Size(104, 24)
    Me.Button2.TabIndex = 2
    Me.Button2.Text = "#Imprimir#"
    '
    'Button3
    '
    Me.Button3.FlatStyle = System.Windows.Forms.FlatStyle.System
    Me.Button3.Location = New System.Drawing.Point(404, 192)
    Me.Button3.Name = "Button3"
    Me.Button3.Size = New System.Drawing.Size(104, 24)
    Me.Button3.TabIndex = 3
    Me.Button3.Text = "#Cancelar#"
    '
    'Button4
    '
    Me.Button4.FlatStyle = System.Windows.Forms.FlatStyle.System
    Me.Button4.Location = New System.Drawing.Point(8, 192)
    Me.Button4.Name = "Button4"
    Me.Button4.Size = New System.Drawing.Size(104, 24)
    Me.Button4.TabIndex = 4
    Me.Button4.Text = "#VistaPreliminar#"
    '
    'frmConfigImprimir
    '
    Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
    Me.ClientSize = New System.Drawing.Size(514, 224)
    Me.Controls.Add(Me.Button4)
    Me.Controls.Add(Me.Button3)
    Me.Controls.Add(Me.Button2)
    Me.Controls.Add(Me.GroupBox2)
    Me.Controls.Add(Me.GroupBox1)
    Me.Icon = CType(resources.GetObject("$this.Icon"), System.Drawing.Icon)
    Me.Name = "frmConfigImprimir"
    Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
    Me.Text = "#OpcionesImpresiones#"
    Me.Controls.SetChildIndex(Me.GroupBox1, 0)
    Me.Controls.SetChildIndex(Me.GroupBox2, 0)
    Me.Controls.SetChildIndex(Me.Button2, 0)
    Me.Controls.SetChildIndex(Me.Button3, 0)
    Me.Controls.SetChildIndex(Me.Button4, 0)
    Me.GroupBox1.ResumeLayout(False)
    Me.GroupBox2.ResumeLayout(False)
    Me.ResumeLayout(False)

  End Sub

#End Region

#Region "Funciones privadas"
  Private Sub ImprimirHoja(ByVal bImprimir As Boolean)
    With pi
      If RadioButton1.Checked = True Then .PrintType = PrintType.All
      If RadioButton2.Checked = True Then .PrintType = PrintType.CellRange
      If RadioButton3.Checked = True Then .PrintType = PrintType.CurrentPage
      If RadioButton4.Checked = True Then
        .PrintType = PrintType.PageRange
        .PageStart = CInt(TextBox2.Text)
        .PageEnd = CInt(TextBox1.Text)
      End If
      .ShowColumnHeaders = CheckBox1.Checked
      .ShowRowHeaders = CheckBox2.Checked
      .ShowGrid = CheckBox3.Checked
      .ShowBorder = CheckBox4.Checked
      .ShowShadows = CheckBox5.Checked
      .ShowColor = CheckBox6.Checked
      .UseMax = CheckBox7.Checked
      '.BestFitCols = CheckBox8.Checked
      '.Printer = "asdfasdfasdfasdfasdf"
      '.ShowPrintDialog = True
      .Preview = bImprimir
      .ZoomFactor = 100
    End With
    frm.WindowState = FormWindowState.Maximized
    frm.grdPrincipal.Sheets(0).PrintInfo = pi
    frm.grdPrincipal.PrintSheet(0)

    Me.Close()

  End Sub

  Public Sub StartPage(ByVal frmM As frmMain)
    frm = frmM

    Me.ShowDialog()
    Me.BringToFront()
  End Sub
#End Region

#Region "Botones"
  Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    Try
      If frmCPag Is Nothing Then frmCPag = New frmConfigPagina

      frmCPag.ShowDialog()

    Catch ex As Exception
      MsgBox(ex.Message, MsgBoxStyle.Critical)
    End Try
  End Sub

  Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
    ImprimirHoja(False)
  End Sub

  Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
    Me.Close()
  End Sub

  Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
    ImprimirHoja(True)
  End Sub
#End Region

#Region "Textboxes"
  Private Sub TextBox1_Validating(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles TextBox1.Validating
    RadioButton4.Checked = True
    If TextBox2.Text <> "" Then
      If Not IsNumeric(TextBox1.Text) Or (CInt(TextBox1.Text) < CInt(TextBox2.Text)) Then
        MsgBox("El numero de Pagina no es valido", 48, "Aviso")
        e.Cancel = True
      End If
    End If
  End Sub

  Private Sub TextBox2_Validating(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles TextBox2.Validating
    RadioButton4.Checked = True
    If TextBox1.Text <> "" Then
      If Not IsNumeric(TextBox2.Text) Or (CInt(TextBox1.Text) < CInt(TextBox2.Text)) Then
        MsgBox("El numero de Pagina no es Valido", 48, "Aviso")
        e.Cancel = True
      End If
    End If
  End Sub
#End Region

  Private Sub frmConfigImprimir_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    cGlobal.CargaEtiquetas(Me.Controls, Me)

    With pi
      Select Case .PrintType
        Case PrintType.All
          RadioButton1.Checked = True
        Case PrintType.CellRange
          RadioButton2.Checked = True
        Case PrintType.CurrentPage
          RadioButton3.Checked = True
        Case PrintType.PageRange
          RadioButton4.Checked = True
      End Select
      CheckBox1.Checked = .ShowColumnHeaders
      CheckBox2.Checked = .ShowRowHeaders
      CheckBox3.Checked = .ShowGrid
      CheckBox4.Checked = .ShowBorder
      CheckBox5.Checked = .ShowShadows
      CheckBox6.Checked = .ShowColor
      'CheckBox7.Checked = .UseMax
      'CheckBox8.Checked = .BestFitCols
      If pi.PageStart <> -1 Then
        TextBox2.Text = pi.PageStart
        TextBox1.Text = pi.PageEnd
      Else
        TextBox2.Text = ""
        TextBox1.Text = ""
      End If
    End With
  End Sub
End Class
